package com.hustmm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.hustmm.domain.MmMaterial;
import com.hustmm.service.IMmMaterialService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 材料主数据Controller
 * 
 * @author WUDI
 * @date 2024-05-23
 */
@RestController
@RequestMapping("/hustmm/MmMaterial")
public class MmMaterialController extends BaseController
{
    @Autowired
    private IMmMaterialService mmMaterialService;

    /**
     * 查询材料主数据列表
     */
    @PreAuthorize("@ss.hasPermi('hustmm:MmMaterial:list')")
    @GetMapping("/list")
    public TableDataInfo list(MmMaterial mmMaterial)
    {
        startPage();
        List<MmMaterial> list = mmMaterialService.selectMmMaterialList(mmMaterial);
        return getDataTable(list);
    }

    /**
     * 导出材料主数据列表
     */
    @PreAuthorize("@ss.hasPermi('hustmm:MmMaterial:export')")
    @Log(title = "材料主数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MmMaterial mmMaterial)
    {
        List<MmMaterial> list = mmMaterialService.selectMmMaterialList(mmMaterial);
        ExcelUtil<MmMaterial> util = new ExcelUtil<MmMaterial>(MmMaterial.class);
        util.exportExcel(response, list, "材料主数据");
    }

    /**
     * 获取材料主数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('hustmm:MmMaterial:query')")
    @GetMapping(value = "/{matId}")
    public AjaxResult getInfo(@PathVariable("matId") String matId)
    {
        return success(mmMaterialService.selectMmMaterialByMatId(matId));
    }

    /**
     * 新增材料主数据
     */
    @PreAuthorize("@ss.hasPermi('hustmm:MmMaterial:add')")
    @Log(title = "材料主数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MmMaterial mmMaterial)
    {
        return toAjax(mmMaterialService.insertMmMaterial(mmMaterial));
    }

    /**
     * 修改材料主数据
     */
    @PreAuthorize("@ss.hasPermi('hustmm:MmMaterial:edit')")
    @Log(title = "材料主数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MmMaterial mmMaterial)
    {
        return toAjax(mmMaterialService.updateMmMaterial(mmMaterial));
    }

    /**
     * 删除材料主数据
     */
    @PreAuthorize("@ss.hasPermi('hustmm:MmMaterial:remove')")
    @Log(title = "材料主数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{matIds}")
    public AjaxResult remove(@PathVariable String[] matIds)
    {
        return toAjax(mmMaterialService.deleteMmMaterialByMatIds(matIds));
    }
}
